﻿using System.Windows;
using System.Windows.Controls;
using Prism.Regions;

namespace Coniometer.Pages.SettingPages
{
    public partial class UserManagementPage : UserControl
    {
        private readonly IRegionManager _regionManager;

        public UserManagementPage(IRegionManager regionManager)
        {
            InitializeComponent();
            _regionManager = regionManager;
            Loaded += UserManagementPage_Loaded;
            UserPageTabControl.SelectionChanged += TabControl_SelectionChanged;
        }

        private void UserManagementPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (UserPageTabControl.Items.Count > 0 && UserPageTabControl.SelectedIndex == -1)
            {
                UserPageTabControl.SelectedIndex = 0;
                NavigateToSelectedTab();
            }
        }

        private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            NavigateToSelectedTab();
        }

        private void NavigateToSelectedTab()
        {
            if (!(UserPageTabControl.SelectedItem is TabItem selectedTab)) return;
            var region = _regionManager.Regions["UserContentRegion"];
            switch (selectedTab.Header.ToString())
            {
                case "用户管理":
                    region.RequestNavigate("ManagementPage");
                    //通知页面刷新数据
                    break;
                case "角色权限":
                    region.RequestNavigate("PermissionPage");
                    //通知页面刷新数据
                    break;
            }
        }
    }
}